//
//  WYTabBar.m
//  Boss
//
//  Created by admin on 2018/6/1.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYTabBar.h"
#import "UIView+Extension.h"
#import "UIImage+DrawWithColor.h"
static const NSInteger ITEMCOUNT = 5;
@interface WYTabBar()<UITabBarDelegate>

@property (nonatomic, strong) UIButton *orderButton;

@property (nonatomic, assign) NSInteger selectedIndex;

@end


@implementation WYTabBar

- (instancetype)init
{
    self = [super init];
    if (self) {
//        UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, -1, [UIScreen mainScreen].bounds.size.width, 1)];
//        topView.backgroundColor = [UIColor lightGrayColor];
       // [self addSubview:topView];
        [self setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]]];
        [self setShadowImage:[UIImage new]];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"icon_tabbar_add_normal"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"icon_tabbar_add_select"] forState:UIControlStateSelected];
        button.bounds = CGRectMake(0, 0, 72, 48+24);
        self.centerBtn = button;
        [button setTitle:@"发布" forState:UIControlStateNormal];
        button.titleEdgeInsets = UIEdgeInsetsMake(34+20, -31, 0, 0);
        button.imageEdgeInsets = UIEdgeInsetsMake(-11.5, 20, 0, 0);
         [button setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
        [button setTitleColor:[UIColor hexStringToColor:@"#999999" alpha:1.0] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:10];

    
        [self addSubview:button];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    if (kDevice_Is_iPhoneX) {
         self.centerBtn.center = CGPointMake(self.width * 0.5-10, self.height * 0.2);
        NSLog(@"%@",NSStringFromCGPoint(self.centerBtn.center));
        
        
    }else{
         self.centerBtn.center = CGPointMake(self.width * 0.5-10, self.height * 0.3);
    }
    
    
    // self.height * 0.2
   
    
    int index = 0;
    CGFloat wigth = self.width / ITEMCOUNT;
    for (UIView *sub in self.subviews) {
        if ([sub isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            sub.x = index * wigth;
            index++;
            if (index == 2) {
                index++;
            }
        }
    }
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
    if (self.isHidden == NO) {
        
        CGPoint newPoint = [self convertPoint:point toView:self.centerBtn];
        
        if ( [self.centerBtn pointInside:newPoint withEvent:event]) {
            return self.centerBtn;
        }else{
            
            return [super hitTest:point withEvent:event];
        }
    }
    
    else {
        return [super hitTest:point withEvent:event];
    }
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    
}








@end
